package com.yanqu.road.server.manager.tomb.event;

import com.yanqu.road.entity.enums.activity.tomb.SwitchTypeEnum;
import com.yanqu.road.pb.tomb.Tomb;
import com.yanqu.road.server.manager.tomb.Position;
import com.yanqu.road.server.manager.tomb.TombActivity;
import com.yanqu.road.server.manager.tomb.TombMaze;
import com.yanqu.road.logic.activity.tomb.config.entity.ActivityTombEvent;
import com.yanqu.road.server.manager.tomb.TombServiceMgr;
import com.yanqu.road.server.manager.tomb.astar.Coordinate;
import com.yanqu.road.server.manager.tomb.entity.*;
import com.yanqu.road.server.protocol.GameErrorCode;

import java.time.ZoneId;
import java.util.*;

public class Buff implements IEvent {
    @Override
    public boolean canStand(DbTombUser dbTombUser, TombMaze tombMaze, Position position) {
        return true;
    }

    @Override
    public boolean canThrough(DbTombUser dbTombUser, TombMaze tombMaze, Position position) {
        return true;

    }

    @Override
    public boolean canExplore(DbTombUser dbTombUser, TombMaze tombMaze, Position position) {
        return false;
    }

    @Override
    public void detail(TombMaze tombMaze, DbTombUser dbTombUser, Position position, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventExploreResp.Builder builder) {
        ActivityTombEvent activityTombEvent = tombMaze.getConfig().getEvents(1).get(0);
        DbTombUserPosition dbTombUserPosition = tombMaze.getActivity().getDbData().getDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
        if (dbTombUserPosition == null) {
            dbTombUserPosition = tombMaze.getActivity().getDbData().initDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
            dbTombUserPosition.setEventId(activityTombEvent.getId());
        }
        if (dbTombUserPosition.getRelationId() > 0) {
            positionTempBuilder.setIsOver(true);
        } else {
            int p1 = activityTombEvent.getParam1().get(0);
            int p2 = activityTombEvent.getParam1().get(1);
            for (Integer integer : dbTombUserPosition.getRelationIdList()) {
                Tomb.PartnerTemp.Builder p = Tomb.PartnerTemp.newBuilder();
                PartnerInfo partnerInfo = dbTombUser.acquirePartnerInfo(integer);
                PartnerUpgradeInfo partnerUpgradeInfo = dbTombUser.acquirePartnerUpgradeInfo(integer);
                p.setId(integer);
                p.setBaseEarn(partnerInfo.getAbility());
                p.setEarn(partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
                p.setUpgradeTimes(partnerUpgradeInfo.getTimes());
                p.setUpgradeValue(partnerUpgradeInfo.getResultUpgradeAbility(partnerInfo.getAbility(), p1, p2) - partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
                p.setPercentage(partnerUpgradeInfo.getPercentage());
                p.setFixedValue(partnerUpgradeInfo.getFixedValue());
                builder.addPartnerList(p);
            }
            positionTempBuilder.setIsOver(false);
        }
        positionTempBuilder.setEventConfig(activityTombEvent.getEventConfigBuilder());
        positionTempBuilder.setEnum(position.getpEnum());
        positionTempBuilder.setEventEnum(position.geteType());
    }

    @Override
    public void explore(TombMaze tombMaze, DbTombUser dbTombUser, DbTombPosition dbTombPosition, Position position, ActivityTombEvent activityTombEvent, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventExploreResp.Builder builder) {
        DbTombUserPosition dbTombUserPosition = tombMaze.getActivity().getDbData().initDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
        dbTombUserPosition.setEventId(activityTombEvent.getId());
    }

    @Override
    public void display(DbTombUser dbTombUser, TombMaze tombMaze, Position position, Tomb.PositionTemp.Builder p) {
        if (position.getFlag() == 0) {
            return;
        }
        DbTombUserPosition dbTombUserPosition = tombMaze.getActivity().getDbData().getDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
        if (dbTombUserPosition == null) {
            p.setIsOver(false);
            return;
        }
        if (dbTombUserPosition.getRelationId() == 0) {
            p.setIsOver(false);
        }
    }


    @Override
    public void info(TombMaze tombMaze, DbTombUser dbTombUser, DbTombPosition dbTombPosition, Position position, ActivityTombEvent activityTombEvent, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventInfoResp.Builder builder) {
        DbTombUserPosition dbTombUserPosition = tombMaze.getActivity().getDbData().getDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
        if (dbTombUserPosition == null) {
            dbTombUserPosition = tombMaze.getActivity().getDbData().initDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
            dbTombUserPosition.setEventId(activityTombEvent.getId());
        }
        if (dbTombUserPosition.getRelationId() > 0) {
            positionTempBuilder.setIsOver(true);
        } else {
            int p1 = activityTombEvent.getParam1().get(0);
            int p2 = activityTombEvent.getParam1().get(1);
            for (Integer integer : dbTombUserPosition.getRelationIdList()) {
                Tomb.PartnerTemp.Builder p = Tomb.PartnerTemp.newBuilder();
                PartnerInfo partnerInfo = dbTombUser.acquirePartnerInfo(integer);
                PartnerUpgradeInfo partnerUpgradeInfo = dbTombUser.acquirePartnerUpgradeInfo(integer);
                p.setId(integer);
                p.setBaseEarn(partnerInfo.getAbility());
                p.setEarn(partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
                p.setUpgradeTimes(partnerUpgradeInfo.getTimes());
                p.setUpgradeValue(partnerUpgradeInfo.getResultUpgradeAbility(partnerInfo.getAbility(), p1, p2) - partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
                p.setPercentage(partnerUpgradeInfo.getPercentage());
                p.setFixedValue(partnerUpgradeInfo.getFixedValue());
                builder.addPartnerList(p);
            }
            positionTempBuilder.setIsOver(false);
        }
        positionTempBuilder.setEventConfig(activityTombEvent.getEventConfigBuilder());
    }

    @Override
    public void touch(TombMaze tombMaze, DbTombUser dbTombUser, DbTombPosition dbTombPosition, Position position, ActivityTombEvent activityTombEvent, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventTouchResp.Builder builder, Tomb.TombEventTouchReq req) {
        DbTombUserPosition dbTombUserPosition = tombMaze.getActivity().getDbData().getDbTombUserPosition(dbTombUser.getGroupId(), tombMaze.getFloor(), dbTombUser.getUserId(), position.getRow(), position.getColumn());
        if (dbTombUserPosition == null) {
            builder.setRet(GameErrorCode.E_ERROR_DATA);
            return;
        }
        int p1 = activityTombEvent.getParam1().get(0);
        int p2 = activityTombEvent.getParam1().get(1);
        int p3 = activityTombEvent.getParam1().get(2);
        int p4 = activityTombEvent.getParam1().get(3);

        //获取【天玄机枢增益事件】开关。如果开，自动选择战力最高门客。
        boolean autoSelectPartnerFlag = dbTombUser.getSwitchByUserAndType(SwitchTypeEnum.TYPE_7.getType());
        if (autoSelectPartnerFlag) {
            if (dbTombUserPosition.getRelationId() > 0) {
                builder.setRet(GameErrorCode.E_TOMB_POSITION_ERROR);
                return;
            }
            //判断是否已经触发过随机
            Set<Integer> partnerIdSet;
            if (!dbTombUserPosition.getRelationIdList().isEmpty()) {
                //已经触发过，用之前随机出来的门客
                partnerIdSet = dbTombUserPosition.getRelationIdList();
            } else {
                //随机出4个门客
                partnerIdSet = tombMaze.randPartnerList(dbTombUser);
            }
            //获取4个门客中，战力最高的
            PartnerInfo maxAbilityPartnerInfo = dbTombUser.getMaxAbilityPartnerInfoByIdList(partnerIdSet);
            //增加门客战力
            this.addPartnerAbility(maxAbilityPartnerInfo.getId(), tombMaze, activityTombEvent, dbTombUser, builder, dbTombUserPosition, position, positionTempBuilder);
            return;
        }

        //无自动选择，走以下选择，确认逻辑
        if (req.getConform()) {
            //确认选择
            if (dbTombUserPosition.getRelationIdList().isEmpty()) {
                builder.setRet(GameErrorCode.E_TOMB_POSITION_ERROR);
                return;
            }
            if (!dbTombUserPosition.getRelationIdList().contains(req.getRelationId())) {
                builder.setRet(GameErrorCode.E_TOMB_PARTNER_NOT_FOUND);
                return;
            }
            if (dbTombUserPosition.getRelationId() > 0) {
                builder.setRet(GameErrorCode.E_TOMB_POSITION_ERROR);
                return;
            }
            //增加门客战力
            this.addPartnerAbility(req.getRelationId(), tombMaze, activityTombEvent, dbTombUser, builder, dbTombUserPosition, position, positionTempBuilder);
        } else {
            //随机出待选择门客LIST
            if (dbTombUserPosition.getRelationIdList().isEmpty()) {
                dbTombUserPosition.getRelationIdList().addAll(tombMaze.randPartnerList(dbTombUser));
                dbTombUserPosition.refreshUpdateTime();
            } else {
                builder.setRet(GameErrorCode.E_TOMB_PARTNER_ALREADY_RAND);
                return;
            }
            //构建PB
            for (Integer integer : dbTombUserPosition.getRelationIdList()) {
                PartnerUpgradeInfo partnerUpgradeInfo = dbTombUser.acquirePartnerUpgradeInfo(integer);
                PartnerInfo partnerInfo = dbTombUser.acquirePartnerInfo(integer);
                Tomb.PartnerTemp.Builder p = Tomb.PartnerTemp.newBuilder();
                p.setId(integer);
                p.setBaseEarn(partnerInfo.getAbility());
                p.setUpgradeTimes(partnerUpgradeInfo.getTimes());
                p.setEarn(partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
                p.setFixedValue(partnerUpgradeInfo.getFixedValue());
                p.setPercentage(partnerUpgradeInfo.getPercentage());
                p.setUpgradeValue(partnerUpgradeInfo.getResultUpgradeAbility(partnerInfo.getAbility(), p1, p2) - partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
                builder.addPartnerList(p);
            }
        }
    }

    /**
     * 增加门客战力
     * @param partnerId
     * @param tombMaze
     * @param activityTombEvent
     * @param dbTombUser
     * @param builder
     * @param dbTombUserPosition
     * @param position
     * @param positionTempBuilder
     */
    private void addPartnerAbility(int partnerId, TombMaze tombMaze, ActivityTombEvent activityTombEvent, DbTombUser dbTombUser,
                                       Tomb.TombEventTouchResp.Builder builder, DbTombUserPosition dbTombUserPosition, Position position,
                                   Tomb.PositionTemp.Builder positionTempBuilder) {
        int limit = activityTombEvent.getParam1().get(3);
        PartnerUpgradeInfo partnerUpgradeInfo = dbTombUser.acquirePartnerUpgradeInfo(partnerId);
        if (partnerUpgradeInfo.getTimes() >= limit) {
            //todo 这里先临时报错经全客户端，如果超过次数的话
            builder.setRet(GameErrorCode.E_ERROR_DATA);
            return;
        }

        int p1 = activityTombEvent.getParam1().get(0);
        int p2 = activityTombEvent.getParam1().get(1);

        PartnerInfo partnerInfo = dbTombUser.acquirePartnerInfo(partnerId);

        dbTombUserPosition.setRelationId(partnerId);
        Tomb.PartnerTemp.Builder p = Tomb.PartnerTemp.newBuilder();
        p.setUpgradeValue(partnerUpgradeInfo.getResultUpgradeAbility(partnerInfo.getAbility(), p1, p2) - partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));

        partnerUpgradeInfo.setTimes(partnerUpgradeInfo.getTimes() + 1);
        partnerUpgradeInfo.setPercentage(partnerUpgradeInfo.getPercentage() + (double) p1 / 1000);
        partnerUpgradeInfo.setFixedValue(partnerUpgradeInfo.getFixedValue() + p2);

        p.setId((int) dbTombUserPosition.getRelationId());
        p.setBaseEarn(partnerInfo.getAbility());
        p.setEarn(partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility()));
        p.setUpgradeTimes(partnerUpgradeInfo.getTimes());
        p.setFixedValue(partnerUpgradeInfo.getFixedValue());
        p.setPercentage(partnerUpgradeInfo.getPercentage());
        positionTempBuilder.setIsOver(true);

        builder.setPartner(p);
        dbTombUserPosition.refreshUpdateTime();

        dbTombUser.refreshUpdateTime();

        builder.setAttack(dbTombUser.getTotalAttack());

            //日志
            DbTombLog dbTombLog = DbTombLog.newInstance();
            dbTombLog.setUid(String.valueOf(dbTombUser.getUserId()));
            dbTombLog.setFloor(tombMaze.getFloor());
            dbTombLog.setFromUserId(dbTombUser.getUserId());
            dbTombLog.setLogEnum(Tomb.TombLogEnum.TombLogEnum_Buff_VALUE);
            dbTombLog.setValue1(partnerId);
            dbTombLog.setX(position.getRow());
            dbTombLog.setY(position.getColumn());
            dbTombLog.setDescription("升级门客");
            dbTombLog.setGroupId(dbTombUser.getGroupId());
            tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog, false);

        //发到游戏服写日志
        Tomb.TombLogCrossToGameReq.Builder logBuilder = Tomb.TombLogCrossToGameReq.newBuilder();
        logBuilder.setLEnum(Tomb.GameTombLogEnum.BUFF);
        logBuilder.setUserId(dbTombUser.getUserId());
        logBuilder.setActivityId(dbTombUser.getActivityId());
        logBuilder.setUnionUid(dbTombUser.getUserInfo().getUnionUid());
        logBuilder.setFloor(dbTombUser.getFloor());
        logBuilder.setX(position.getRow());
        logBuilder.setY(position.getColumn());
        logBuilder.setHp(dbTombUser.getHp());
        logBuilder.setTimestamp(System.currentTimeMillis());
        Tomb.TombLogBuff.Builder log = Tomb.TombLogBuff.newBuilder();
        log.setRelationId(partnerId);
        log.setAbility(partnerUpgradeInfo.getResultUpgradeAbility(partnerInfo.getAbility(), p1, p2));
        log.setTotalAbility(dbTombUser.getTotalAttack());
        logBuilder.setBuff(log);
        tombMaze.getActivity().sendLogToGame(dbTombUser, logBuilder);
    }

    /**
     * 一键强化所有门客
     *
     * @param groupId    区分组ID
     * @param dbTombUser 玩家在活动里的数据
     * @param builder    待返回协议
     * @param activity   活动信息
     * @param tombMaze   当前地图信息
     */
    public void oneClickBuff(int groupId, DbTombUser dbTombUser, Tomb.TombOneClickJumpResp.Builder builder,
                             TombActivity activity, TombMaze tombMaze) {
        ActivityTombEvent activityTombEvent = activity.getConfig().getEvents(1).get(0); // t_s_activity_tomb_event
        DbActivityTombInfo dbActivityTombInfo = activity.getDbData().getDbActivityTombInfo(dbTombUser.getGroupId()); // t_c_activity_tomb_user_position

        int maxExploreFloor = dbActivityTombInfo.getMaxExploreFloor(); // 当前已解锁最深层数
        Map<Integer, TombMaze> mazeMap = activity.getTombMazeMap().get(groupId); // 活动陵墓地图集合

        // 特殊处理情况，假设玩家在第1层，当前11层boss已被击杀发现入口，但是未有玩家进入12层，此时一键跳转到12层
        if (mazeMap.containsKey(maxExploreFloor)) {
            TombMaze maze = mazeMap.get(maxExploreFloor);
            String posKey = maze.getDbTombMaze().getEliteNpcEvent(); // 当前层守关精英位置
            // 获取当前层守关精英事件信息，判断是否有玩家处理了该事件
            DbTombPosition dbTombPosition = activity.getDbData().getDbTombPosition(groupId, maxExploreFloor, posKey);
            if (dbTombPosition != null && dbTombPosition.getFinishUserId() > 0) {
                maxExploreFloor++;
            }
        }
        int curFloor = tombMaze.getFloor(); // 当前层数
        // 判断最深层与当前层是否相隔一层以上
        if (curFloor + 1 >= maxExploreFloor) {
            builder.setRet(GameErrorCode.E_TOMB_CAN_NOT_MOVE);
            return;
        }

        Map<Integer, Tomb.PartnerTemp.Builder> upgradeInfos = new HashMap<>(); // 门客强化列表
        boolean flg = false; // 判断是否还有门客可以选择
        for (int i = curFloor; i < maxExploreFloor; i++) { // 逐层遍历天玄枢机并执行入库
            if (mazeMap.containsKey(i)) {
                TombMaze tmpMaze = mazeMap.get(i); // 每层地图信息
                Map<String, Position> buffEventMap = tmpMaze.getBuffEventMap(); // 每层天玄枢机信息
                for (Map.Entry<String, Position> entry : buffEventMap.entrySet()) {
                    Position pos = entry.getValue();
                    DbTombUserPosition dbPos = activity.getDbData().getDbTombUserPosition(groupId, tombMaze.getFloor(),
                            dbTombUser.getUserId(), pos.getRow(), pos.getColumn());
                    if (curFloor == i && isNeedCleared(dbTombUser, tombMaze, pos, dbPos)) { // 当前层特殊判断
                        continue;
                    }

                    if (dbPos == null) { // 初始化玩家在天玄枢机的位置信息
                        dbPos = tombMaze.getActivity().getDbData().initDbTombUserPosition(dbTombUser.getGroupId(),
                                tmpMaze.getFloor(), dbTombUser.getUserId(), pos.getRow(), pos.getColumn());
                        dbPos.setEventId(activityTombEvent.getId());
                    }

                    Set<Integer> partnerIdSet;
                    if (!dbPos.getRelationIdList().isEmpty()) { //已经触发过，用之前随机出来的门客
                        partnerIdSet = dbPos.getRelationIdList();
                    } else { //随机出4个门客
                        partnerIdSet = tombMaze.randPartnerList(dbTombUser);
                    }

                    if (partnerIdSet.isEmpty()) { // 没有待强化门客
                        flg = true;
                        break;
                    }

                    PartnerInfo partner = dbTombUser.getMaxAbilityPartnerInfoByIdList(partnerIdSet); // 获取4个门客中，战力最高的
                    int partnerId = partner.getId();
                    PartnerUpgradeInfo partnerUpgradeInfo = dbTombUser.acquirePartnerUpgradeInfo(partnerId);
                    long abilityBefore = partnerUpgradeInfo.getResultAbility(partner.getAbility());

                    addPartnerAbility(partner.getId(), tmpMaze, activityTombEvent, dbTombUser,
                            Tomb.TombEventTouchResp.newBuilder(), dbPos, pos, Tomb.PositionTemp.newBuilder()); // 调用原有逻辑

                    // 获取门客强化信息，判断是否有在当前层被强化过
                    Tomb.PartnerTemp.Builder partnerBuilder = upgradeInfos.getOrDefault(partnerId, Tomb.PartnerTemp.newBuilder());
                    partnerBuilder.setId(partnerId);
                    partnerBuilder.setUpgradeTimes(partnerBuilder.getUpgradeTimes() + 1);
                    long abilityAfter = partnerUpgradeInfo.getResultAbility(partner.getAbility());
                    partnerBuilder.setUpgradeValue((abilityAfter - abilityBefore + partnerBuilder.getUpgradeValue()));
                    upgradeInfos.put(partnerId, partnerBuilder);
                }
                if (flg) { // 没有待强化门客，提前退出
                    break;
                }
            }
        }

        List<Tomb.PartnerTemp> upgradeList = new ArrayList<>();
        for (Map.Entry<Integer, Tomb.PartnerTemp.Builder> entry : upgradeInfos.entrySet()) { // 装载返回信息
            Tomb.PartnerTemp.Builder value = entry.getValue();
            value.setUpgradeValue((long) (value.getUpgradeValue() * (1 + (double) dbTombUser.getAttackAddition() / 1000)));
            upgradeList.add(value.build());
        }
        builder.addAllUpgradeList(upgradeList);
        builder.setAttack(dbTombUser.getTotalAttack()); // 显示升级后的战力总和

        enterMaxExploreFloor(groupId, dbTombUser, activity, maxExploreFloor, tombMaze);
    }

    /**
     * 特殊判断当前层天玄枢机是否需要被处理，不可达，已处理等就跳过
     *
     * @param dbTombUser 玩家信息
     * @param tombMaze   陵墓地图信息
     * @param pos        天玄枢机信息
     * @param dbPos      天玄枢机处理记录
     * @return boolean
     */
    private boolean isNeedCleared(DbTombUser dbTombUser, TombMaze tombMaze, Position pos, DbTombUserPosition dbPos) {
        if (!tombMaze.inSamePathArea(dbTombUser,
                Coordinate.newInstance(pos.getRow(), pos.getColumn()))) { // 判断是否可达
            return true;
        }

        // 获取玩家的位置信息， 如果不为空且天玄枢机已被处理
        return dbPos != null && dbPos.getRelationId() > 0;
    }

    /**
     * 进入已解锁最深层，设置玩家的初始位置
     *
     * @param groupId         区分组ID
     * @param dbTombUser      玩家在活动里的数据
     * @param activity        活动信息
     * @param maxExploreFloor 当前已解锁的最深层
     * @param tombMaze        当前地图信息
     */
    private static void enterMaxExploreFloor(int groupId, DbTombUser dbTombUser, TombActivity activity,
                                             int maxExploreFloor, TombMaze tombMaze) {
        Tomb.CoordinateTemp.Builder coordinateTempBuilder = Tomb.CoordinateTemp.newBuilder();
        coordinateTempBuilder.setRow(dbTombUser.getX());
        coordinateTempBuilder.setColumn(dbTombUser.getY());
        coordinateTempBuilder.setFloor(dbTombUser.getFloor());

        Tomb.AllyInfo.Builder allyInfoBuilder = dbTombUser.toAllyInfoBuilder();
        // 初始化到新楼层的坐标
        activity.moveNotify(maxExploreFloor, coordinateTempBuilder.build(), dbTombUser, null, allyInfoBuilder);
        dbTombUser.setFloor(maxExploreFloor);
        Coordinate birthplace = activity.getTombMaze(groupId, maxExploreFloor).getBirthplace(dbTombUser);
        dbTombUser.setX(birthplace.getX());
        dbTombUser.setY(birthplace.getY());
        dbTombUser.refreshUpdateTime();
        dbTombUser.setGoDownstairs(0);

        // 玩家跳转日志 -- 跨服
        DbTombLog dbTombLog = DbTombLog.newInstance();
        dbTombLog.setUid(String.valueOf(activity.getActivityInfo().getActivityId()));
        dbTombLog.setFloor(maxExploreFloor);
        dbTombLog.setFromUserId(dbTombUser.getUserId());
        dbTombLog.setEnergy(dbTombUser.getEnergy(tombMaze.getConfig().getConfig()));
        dbTombLog.setDescription("一键跳转到已解锁最深层");
        dbTombLog.setX(dbTombUser.getX());
        dbTombLog.setY(dbTombUser.getY());
        dbTombLog.setGroupId(groupId);
        tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog, true);
    }
}
